php pluck from array of objects

57

php pluck from array of objects -

$cats = [
  0 => { 'id': 15 },
  1 => { 'id': 18 },
  2 => { 'id': 23 }
]
  
$idCats = array_column($cats, 'id');

laravel array_pluck -

$array = [
    ['developer' => ['id' => 1, 'name' => 'Taylor']],
    ['developer' => ['id' => 2, 'name' => 'Abigail']],
];

$array = array_pluck($array, 'developer.name');

// ['Taylor', 'Abigail'];

Comments

Submit
0 Comments